package shichenyang;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.Template;
/**
 * 生成表设计
 * @author shichenyang89@gmail.com
 *
 */
public class FreeMarker {
	
	private Configuration configuration=null;
	
	@SuppressWarnings("deprecation")
	public FreeMarker() {
		configuration =new Configuration();
		configuration.setDefaultEncoding("utf-8");
	}
	
	public void create () throws Exception{
		Map<String, Object> map=new HashMap<String, Object>();
		
		SelectTableSql updateSql=new SelectTableSql();
		configuration.setClassForTemplateLoading(this.getClass(), "/ftl/");
		Template template=configuration.getTemplate("info.ftl");
		 File outFile = new File("D:/outFile.doc");
		
		 if (!outFile.getParentFile().exists()){
             outFile.getParentFile().mkdirs();
         }
		 
		 Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));
		 List<Table> tables=updateSql.getSchema();
		 map.put("tables", tables);
		 template.process(map, out);
		 
	}
	
	public static void main(String[] args) throws Exception {
		new FreeMarker().create();
	}

}
